package com.lz.football.module.guide.view
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.greensock.TweenLite;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.GuideEvent;
	import com.liangzhong.events.LoginEvent;
	import com.liangzhong.events.NotifierEvent;
	import com.lz.football.module.guide.Guide;
	import com.lz.football.module.main.view.TopPanel;
	import com.lz.football.module.sign.view.LoginSignView;
	
	import flash.display.InteractiveObject;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	import lz.controls.managers.AnimationManager;

	/**
	 *签到引导 
	 * @author lake
	 * 
	 */	
	public class SignGuideView extends Guide
	{
		public function SignGuideView()
		{
			super();
		}
		/**
		 *初始化 
		 */		
		override protected function initView():void
		{
			super.initView();
			TweenLite.delayedCall(.2,getFuncIcon);
		}
		/**
		 *获得按钮
		 */		
		private function getFuncIcon():void
		{
			GlobalDef.GameWindowContainer.addChild(bgMark);
			sceneBtn = Reflection.createInstance("com.football.main.signBtn");
			(sceneBtn as InteractiveObject).mouseEnabled = false;
			TopPanel.signBtn.visible = false;
			var entP :Point = TopPanel.signBtn.localToGlobal(new Point(-22,-22));
			
			var appearMc :MovieClip = Reflection.createInstance("com.football.guide.AppearAtSkin");
			DisplayObjectUtil.removeAllChildren(appearMc.mc.mc);
			appearMc.mc.mc.addChild(sceneBtn);
			(sceneBtn as InteractiveObject).mouseEnabled = false;
			addDispToStage(appearMc);
			AnimationManager.moveToThing(new Point(appearMc.x,appearMc.y),appearMc,entP,{delay:1,overwrite:0},.5);
			TweenLite.delayedCall(1.5,showFuncIcon);
		}
		/**
		 *显示按钮 
		 * 
		 */		
		private function showFuncIcon():void
		{
			TopPanel.signBtn.visible = true;
			TopPanel.resizeBtnPos();
			removeBgMark();
			//限制区域
			var rectPoint :Point = TopPanel.signBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,TopPanel.signBtn.width,TopPanel.signBtn.height);
			step();
			//指向图标按钮
			var arrrowPoint :Point = new Point(curClickRect.x + curClickRect.width/3,curClickRect.y + curClickRect.height);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,180);
			sceneBtn =  TopPanel.signBtn;
			arrowAngle = 180;
			//事件
			AppEventDispatcher.getInstance().addEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete2);
		}
		/**
		 *界面显示
		 * @param e
		 * 
		 */		
		private function onLoadResComplete2(e :Event):void
		{
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete2);
			removeBgMark();
			//限制区域
			var rectPoint :Point = LoginSignView.signBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,LoginSignView.signBtn.width,LoginSignView.signBtn.height);
			step();
			//指向签到
			var arrrowPoint :Point = new Point(curClickRect.x - 10,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,-90);
			sceneBtn =  LoginSignView.signBtn;
			arrowAngle = -90;
			//事件
			AppEventDispatcher.getInstance().addEventListener(LoginEvent.USER_SIGN,signH);
		}
		/**
		 *签到 
		 * @param e
		 * 
		 */		
		private function signH(e :Event):void
		{
			AppEventDispatcher.getInstance().removeEventListener(LoginEvent.USER_SIGN,signH);
			//提交引导
			AppEventDispatcher.getInstance().dispatchEvent(new GuideEvent(GuideEvent.POST_GUIDE,{step:8}));
			//限制区域
			var rectPoint :Point = LoginSignView.CLoseBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,LoginSignView.CLoseBtn.width,LoginSignView.CLoseBtn.height);
			step();
			//指向关闭按钮
			var arrrowPoint :Point = new Point(curClickRect.x + curClickRect.width + 10,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,90);
			sceneBtn =  LoginSignView.CLoseBtn;
			arrowAngle = 90;
			//事件
			AppEventDispatcher.getInstance().addEventListener("Guide_Sign_View_Remove",signRemoveH);
		}
		/**
		 *界面移除 
		 * @param e
		 */		
		private function signRemoveH(e :Event):void
		{
			AppEventDispatcher.getInstance().removeEventListener("Guide_Sign_View_Remove",signRemoveH);
			//第8步刷新
			AppEventDispatcher.getInstance().dispatchEvent(new GuideEvent(GuideEvent.POST_GUIDE+"_refresh",{step:8}));
			
			clear();
		}
		/**
		 *执行 
		 * 
		 */		
		override public function process():void
		{
			initView();
		}
		/**
		 *清理 
		 * 
		 */		
		override public function clear():void
		{
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete2);
			AppEventDispatcher.getInstance().removeEventListener(LoginEvent.USER_SIGN,signH);
			AppEventDispatcher.getInstance().removeEventListener("Guide_Sign_View_Remove",signRemoveH);
			super.clear();
		}
	}
}